<?php
// DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
$jQuery = true;
$tinyMCE = true;
$jQueryCookie = true;
$hoverIntent = true;
$Jededitable = true;
$sectionSort = true;
$googleAPI = false;
$calendar = false;
$pageTitle = 'Soberpress - Administration - Events';
$helpKey = 'eventsForm';
require_once ('../../config/include_paths.php');
require_once('config.php');
require_once ('functions.php');
require_once('dbconnect.php');	// database connect script.
session_start();

if ($_SESSION['logged_in'] == 0) {
	require ('security_check.php');
} else {
		// Get form information if editing
		$id = $_GET['id']; 
		if ($id) 
		{
			$sql = "SELECT * FROM events WHERE id='".$_GET['id']."'";
					
			$result =  mysql_query($sql)
			or die(mysql_error());
			
			// Get each row of data on each iteration until
			// there is no more rows
			while ($row = mysql_fetch_assoc($result)) {
				$id = $row['id'];
				$title = $row['title'];
				$editHTML = $row['editHTML'];
				$file = $row['file'];
				$eventDate=$row['eventDate'];
				$eventEndDate=$row['eventEndDate'];
				$eventStartTime = $row['eventStartTime'];
				$eventEndTime = $row['eventEndTime'];
				$lasteditor = $row['editor'];	
				$editdate = $row['editdate'];
			}
			//if there was no event end date it is stored like this, replace with empty string
			if ($eventEndDate == '0000-00-00') {
				$eventEndDate = '';
			}
			// if no start time was selected we stored as like this, replace with empty string
			if ($eventStartTime == '00:00:01') {
				$eventStartTime = '';
			}
			// if no end time was selected we stored as like this, replace with empty string
			if ($eventEndTime == '00:00:01') {
				$eventEndTime = '';
			}
		  }
require_once ('adminhead.php');
?>
<body onLoad="checkMenuSettings(); loadTinyMCE();">
<div id="wrapper">
    <?php require_once ('adminHeader.php'); ?>
  <div class="clearfloat">&nbsp;</div>
  <div id="sidebar">
   <?php require_once ('adminNav.php'); ?>
  </div>
  <div id="main_content">
    <form id="htmlEditor" action="processForm.php" method="post" name="htmlEditor" enctype="multipart/form-data">
      <table>
        <tr>
          <td class="tdRight">Event Title:</td>
          <td colspan="8" class="tdLeft">
              <input name="title" id="title" type="text" size="50" value="<?php echo $title?>" class="colorInput">
          </td>
        </tr>
        <tr>
          <td class="tdRight">Event Date:</td>
          <td class="tdLeft">
              <input name="eventDate" id="eventDate" type="text" size="10" value="<?php echo $eventDate?>" class="colorInput">
          </td>
          <td class="tdRight">(optional) End Date:</td>
          <td class="tdLeft">
              <input name="eventEndDate" id="eventEndDate" type="text" size="10" value="<?php echo $eventEndDate?>" class="colorInput">
          </td>
          <td class="tdRight">Start Time:</td>
          <td class="tdLeft">
              <?php displayTime('eventStartTime',$eventStartTime) ?>
          </td>
          <td class="tdRight">End Time:</td>
          <td class="tdLeft">
              <?php displayTime('eventEndTime',$eventEndTime) ?>
          </td>
        </tr>
        <tr>
          <td bgcolor="#feffff" colspan="8" class="tdLeft">
              <textarea id='editHTML' name='editHTML' rows='20' cols='80'><?php echo $editHTML ?></textarea>
          </td>
        </tr>
        <tr>
          <td class="tdRight">File:</td>
          <td colspan="7" class="tdLeft">
          		<?php if($id){
                 echo   "<span id='currentFile'>$file</span>&nbsp;&nbsp;<input name='changeFile' id='changeFile' type='button'
				 		 value='Change-Upload File'>";
                     } else { 
            	 echo  "<input id='file' name='file' type='file' class='colorInput'/>";
              		 } ?>
          </td>
        </tr>
        <tr>
        <td colspan="8" style="line-height:1.5em;">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"></td><td class="tdCenter"><input type="submit" name="submit" value="Submit" class="groovybutton" /></td>
          <td  colspan="5" class="tdLeft"><input type="reset" class="groovybutton"/></td>
        </tr>
        <tr>
        <td colspan="8" style="line-height:1.5em;">&nbsp;</td>
        </tr>
        <?php
	//if admin display last editor and date
	if ($_SESSION['admin'] == 1) {
	/* format date for display */
				$current_editdate = strtotime($editdate);
				$displaydate = date('m/d/Y g:i:s A', $current_editdate);							
	echo "<tr>
			<td align =\"right\"><strong>Last Editor:</strong></td><td>$lasteditor</td>
			<td align =\"right\"><strong>Last Edit Date/Time:</strong></td><td>$displaydate</td>
		  </tr>";  } ?>
        <input type="hidden" name="editor" value="<?php echo $_SESSION['username'] ?>" />
        <input type="hidden" name="id" value="<?php echo $id ?>" />
        <input type="hidden" name="tableID" value="events" />
        <input type="hidden" name="currentFile" id="currentFile" value="<?php echo $file ?>" />
       </table>
    </form>
  </div>
  <script language="javascript" type="text/javascript">
var table = '<?php echo $tableID ?>';
</script>
</div>
</div>
</body>
</div>
</div>
<?php mysql_close($conn);} ?>
</body>
</html>